<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>培训计划</title>
<script type="text/javascript" src="../static/easyui/jquery.min.js"></script>
<script type="text/javascript" src="../static/easyui/jedate.min.js"></script>
<script type="text/javascript" src="../static/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../static/easyui/locale/easyui-lang-zh_CN.js"></script>
<link rel="stylesheet" href="../static/easyui/themes/icon.css">
<link rel="stylesheet" href="../static/easyui/themes/metro-orange/easyui.css">
<link rel="stylesheet" href="../static/easyui/themes/metro-red/window.css">
<link rel="stylesheet" href="../static/ttt/css/TrainingPlan.css?<%=Math.random()%>">
<script type="text/javascript" src="../static/ttt/js/TrainingPlan.js?<%=Math.random()%>"></script>

<style type="text/css">

</style>
</head>

<body>
<script type="text/javascript">
function plan_tables(){
	$('#TrainingPlantable').datagrid({    
		 url:'TrainingPlantables', //数据源地址
	   columns:[[    
	   	{field:'planid',fixed:false,width:100,title:'计划编号',align:'center'},    
	       {field:'planname',fixed:false,width:100,title:'计划名称',align:'center'},    
	       {field:'EMPNAME',fixed:false,width:100,title:'审批人',align:'center'},
	       {field:'EMPNAMES',fixed:false,width:100,title:'创建人',align:'center'},
	       {field:'PLANYY',fixed:false,width:100,hidden:true,title:'培训原因',align:'center'},
	       {field:'PLANNR',fixed:false,width:100,hidden:true,title:'培训内容',align:'center'},
	       {field:'PLANTS',fixed:false,width:100,hidden:true,title:'培训天数',align:'center'},
	       {field:'plandd',fixed:false,width:100,title:'培训地点',align:'center'},
	       {field:'PLANNIND',fixed:false,width:100,title:'开始时间',align:'center',
	    	   formatter : function(value){
	        		var d = new Date(value);
	        		var times=d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate();
	        		return times;
	        	}   
	       } ,
	       {field:'PLANMAXD',fixed:false,width:100,title:'结束时间',align:'center',
	    	   formatter : function(value){
	        		var d = new Date(value);
	        		var times=d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate();
	        		return times;
	        	}   
	       } ,
	       {field:'PLANSTATE',fixed:false,width:100,title:'状态',align:'center',
	    	   formatter : function(value){
	    		   if(value==0){
	        			return "<span style='color:blue;'>未送审</span>";
	        		}else if(value==1){
	        			return "<span style='color:red;'>送审中</span>";
	        		}else if(value==2){
	        			return "<span style='color:rgb(77,216,123);'>已审核</span>";
	        		}else if(value==3){
	        			return "<span style='color:black;'>已转</span>";
	        		}

	        	}	   
	       } ,
	       {field:'caozuo',fixed:false,width:200,formatter:plan_formatter,title:'操作',align:'center'} 
	       
			    
	   ]],
	   pagination:true,
	   pageNumber:1,
	   pageSize:5,
	   pageList:[5,10,15] 
	}); 	
}
$(function(){
	plan_tables();
	//新增/.,mnxz3
	$("#addTrainingPlan").click(function(){
		$("#queding").text("提交")
		//计划名称
		$("#addTrainingPlan_win_jihuanametext").val("");
		$("#addTrainingPlan_win_jihuanametext").removeAttr("readonly");
		//审批人
/* 		$(".nsb").val();
		$("#addTrainingPlan_win_chuangjianrentext").attr("disabled",false); */
		//开始时间
		$("#addTrainingPlan_win_strattiametext").datebox("setValue","");
		$("#addTrainingPlan_win_strattiametext").attr("disabled",false);
		//结束时间
		$("#addTrainingPlan_win_endtimetext").datebox("setValue","");
		$("#addTrainingPlan_win_endtimetext").attr("disabled",false);
		//计划天数PLANTS
		$("#addTrainingPlan_win_daystext").val("");
		//培训地点
		$("#addTrainingPlan_win_placetext").val("");
		$("#addTrainingPlan_win_placetext").removeAttr("readonly");
		//培训内容
		$("#addPaymentt_win_TrainingContents").val("");
		$("#addPaymentt_win_TrainingContents").removeAttr("readonly");
		//培训原因
		$("#addPaymentt_win_TrainingReasons").val("");
		$("#addPaymentt_win_TrainingReasons").removeAttr("readonly");
		$("#addTrainingPlan_win").window("open");
	})
	//关闭窗口
	$("#quxiao").click(function(){
		$("#addTrainingPlan_win").window("close");
	})
	//新增确定
	$("#queding").click(function(){
		if($("#queding").text()=="提交"){
			//培训名称
			var planname=$("#addTrainingPlan_win_jihuanametext").val();
			//培训地点
			var plandd=$("#addTrainingPlan_win_placetext").val();
			//计划天数
			var plants=$("#addTrainingPlan_win_daystext").val();
			//开始时间
			var planninds=$("#addTrainingPlan_win_strattiametext").val();
			//结束时间
			var planmaxds=$("#addTrainingPlan_win_endtimetext").val()
			//内容
			var plannr=$("#addPaymentt_win_TrainingContents").val()
			//原因
			var planyy=$("#addPaymentt_win_TrainingReasons").val();
			//审批人
			var shenpiren=$(".nsb").attr("id")
			var myDate = new Date();
			var DateStart = new Date(planninds);
			var moth=(myDate.getMonth()+1);
			var date=myDate.getDate()
			var DATE_FORMAT = /^[0-9]{4}-[0-1]?[0-9]{1}-[0-3]?[0-9]{1}$/;	
		/* 	if((DateStart.getMonth()+1)<moth||(DateStart.getMonth()+1)>=moth&&DateStart.getDate()<date){
				alert("开始时间不能低于/等于今天")
			}else  */if(planname==""){

				alert("请输入培训名称！")
			}else if(plandd==""){
				alert("请输入培训地点！")
			}else if(planninds==""&&planmaxds==""){
				alert("请选择开始时间或结束时间！")
			}else if(plants==""){
				alert("培训天数不能为空！")
			}else if(planname!=""&&plandd!=""&&planninds!=""&&planmaxds!=""&&plants!=""){
				if(DATE_FORMAT.test(planninds)&&DATE_FORMAT.test(planmaxds)){
					if(plannr==""){
						plannr="无内容"
					}
					if(planyy==""){
						planyy="无原因"
					}
					$.ajax({
						type:"post",
						url:'add_plan', //数据源地址
						data:{
							planname:planname,
							plandd:plandd,
							plants:plants,
							planninds:planninds,  
							planmaxds:planmaxds,
							plannr:plannr,
							planyy:planyy,
							shenpiren:shenpiren
						},
						success:function(data){  
							plan_tables();
						}
						
					});
				$("#addTrainingPlan_win").window("close");
				}else{
					alert("您的日期输入有误，请重新输入！")
				}
				
			}
		}else if($("#queding").text()=="保存"){
			//计划id
			var rows=$("#TrainingPlantable").datagrid("getChecked");
			//培训名称
			var planname=$("#addTrainingPlan_win_jihuanametext").val();
			//培训地点
			var plandd=$("#addTrainingPlan_win_placetext").val();
			//计划天数
			var plants=$("#addTrainingPlan_win_daystext").val();
			//开始时间
			var planninds=$("#addTrainingPlan_win_strattiametext").val();
			//结束时间
			var planmaxds=$("#addTrainingPlan_win_endtimetext").val()
			//内容
			var plannr=$("#addPaymentt_win_TrainingContents").val()
			//原因
			var planyy=$("#addPaymentt_win_TrainingReasons").val();
			//审批人
			var shenpiren=$(".nsb").attr("id")

			var DATE_FORMAT = /^[0-9]{4}-[0-1]?[0-9]{1}-[0-3]?[0-9]{1}$/;
			if(planname!=""&&plandd!=""&&planninds!=""&&planmaxds!=""&&plants!=""){
				if(DATE_FORMAT.test(planninds)&&DATE_FORMAT.test(planmaxds)){
					if(plannr==""){
						plannr="无内容"
					}
					if(planyy==""){
						planyy="无原因"
					}
					$.ajax({
						type:"post",
						url:'tupdate_plan', //数据源地址
						data:{
							planid:rows[0].planid,
							planname:planname,
							plandd:plandd,
							plants:plants,
							planninds:planninds,  
							planmaxds:planmaxds,
							plannr:plannr,
							planyy:planyy,
							shenpiren:shenpiren
						},
						success:function(data){  
							plan_tables();
						}
						
					});
				$("#addTrainingPlan_win").window("close");
				}else{
					alert("您的日期输入有误，请重新输入！")
				}
				
			}else if(planname==""){
				alert("请输入培训名称！")
			}else if(plandd==""){
				alert("请输入培训地点！")
			}else if(planninds==""&&planmaxds==""){
				alert("请选择开始时间或结束时间！")
			}else if(plants==""){
				alert("培训天数不能为空！")
			}
		}else if($("#queding").text()=="确定"){
			$("#addTrainingPlan_win").window("close");
		}
		
	})
	//计算天数
	$("#addTrainingPlan_win_daystext").click(function(){
		if($("#addTrainingPlan_win_strattiametext").val()!=""&&$("#addTrainingPlan_win_endtimetext").val()!=""){
			//开始时间
			var planninds=$("#addTrainingPlan_win_strattiametext").val();
			//结束时间
			var planmaxds=$("#addTrainingPlan_win_endtimetext").val();
			var DateStart = new Date(planninds);
			var DateEnd = new Date(planmaxds);
			var moth=0;
			moth=(DateEnd.getMonth() - DateStart.getMonth());
			var plant = (DateEnd.getDate() - DateStart.getDate());
			if(moth==0){
				$("#addTrainingPlan_win_daystext").val(plant+1);
			}else if(moth>0){
				$("#addTrainingPlan_win_daystext").val((plant+1)+moth*30);
			}else if(moth<0){
				$("#addTrainingPlan_win_daystext").val("");
				plant="";
			}
			$("#addTrainingPlan_win_daystext").attr("readonly",true);
			if($("#addTrainingPlan_win_daystext").val()<=1){
				alert("培训天数不能少于1天，请核对您的开始时间与结束时间，谢谢!");
				$("#addTrainingPlan_win_daystext").val("");
				plant="";
			}else if($("#addTrainingPlan_win_daystext").val()>60){
				alert("培训天数不能大于60天，请核对您的开始时间与结束时间，谢谢!");
				$("#addTrainingPlan_win_daystext").val("");
				plant="";
			}
		}else{
			$.messager.show({
				title:'信息提示',
				msg: '请填写开始时间与结束时间',
				timeout:1500,  //1秒后消失
				showType:'slide',//弹出的方式。类似ppt里的图片弹出方式
				//弹出框的样式。居中显示
				style:{
					right:'',
					top:document.body.scrollTop+document.documentElement.scrollCenter,
					bottom:''
				}
			});
		}
	})
	//根据计划ID查询
	$("#selectTrainingPlan").click(function(){
		var text=$("#plansname").val();
		if(text!=""){
			$('#TrainingPlantable').datagrid({    
				url:'TrainingPlantables_name', //数据源地址
				queryParams: {  		
				   text:text 		
				},
			   columns:[[    
			   	{field:'planid',fixed:false,width:100,title:'计划编号',align:'center'},    
			       {field:'planname',fixed:false,width:100,title:'计划名称',align:'center'},    
			       {field:'EMPNAME',fixed:false,width:100,title:'审批人',align:'center'},
			       {field:'EMPNAMES',fixed:false,width:100,title:'创建人',align:'center'},
			       {field:'PLANYY',fixed:false,width:100,hidden:true,title:'培训原因',align:'center'},
			       {field:'PLANNR',fixed:false,width:100,hidden:true,title:'培训内容',align:'center'},
			       {field:'PLANTS',fixed:false,width:100,hidden:true,title:'培训天数',align:'center'},
			       {field:'plandd',fixed:false,width:100,title:'培训地点',align:'center'},
			       {field:'PLANNIND',fixed:false,width:100,title:'开始时间',align:'center',
			    	   formatter : function(value){
			        		var d = new Date(value);
			        		var times=d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate();
			        		return times;
			        	}   
			       } ,
			       {field:'PLANMAXD',fixed:false,width:100,title:'结束时间',align:'center',
			    	   formatter : function(value){
			        		var d = new Date(value);
			        		var times=d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate();
			        		return times;
			        	}   
			       } ,
			       {field:'PLANSTATE',fixed:false,width:100,title:'状态',align:'center',
			    	   formatter : function(value){
			    		   if(value==0){
			        			return "<span style='color:blue;'>未送审</span>";
			        		}else if(value==1){
			        			return "<span style='color:red;'>送审中</span>";
			        		}else if(value==2){
			        			return "<span style='color:rgb(77,216,123);'>已审核</span>";
			        		}else if(value==3){
			        			return "<span style='color:black;'>已转</span>";
			        		}

			        	}	   
			       } ,
			       {field:'caozuo',fixed:false,width:200,formatter:plan_formatter,title:'操作',align:'center'} 
			       
					    
			   ]]
			}); 	
		}else if(text==""){
			plan_tables();
		}
	})
})
//在每个操作列里面添加编辑，查看，明细，删除
function plan_formatter(value, row, index) {
	if(row["PLANSTATE"]==2){
		return "<span class='spanclass' onclick='plan_chakan()'>查看</span>/\
		<span class='spanclass' onclick='plan_zhuanxiangmu()'>转培训项目</span>";
	}else if(row["PLANSTATE"]==0){
		return "<span class='spanclass' onclick='plan_songshen()'>送审</span>/\
		<span class='spanclass' onclick='plan_bianji()'>编辑</span>";
	}else{
		return "<span class='spanclass' onclick='plan_chakan()'>查看</span>";
	}
}
//送审
function plan_songshen(){
	var rows=$("#TrainingPlantable").datagrid("getChecked");
	$.ajax({
		type:"post",
		url:'plan_songshen', //数据源地址
		data:{
			planid:rows[0].planid
		},
		success:function(data){ 
			plan_tables();
		}
	})
}
//转培训项目
function plan_zhuanxiangmu(){
	var rows=$("#TrainingPlantable").datagrid("getChecked");
	$.ajax({
		type:"post",
		url:'updatePlan', //数据源地址
		data:{
			id:rows[0].planid
		},
		success:function(data){ 
			var text='新增培训项目';
			var url="ttt/add-training-project";
			adds(text,url);
		}
	})
}
function plan_bianji(){
	var rows=$("#TrainingPlantable").datagrid("getChecked");
		//计划名称
		$("#addTrainingPlan_win_jihuanametext").val(rows[0].planname);
		//审批人
		//$(".nsb").val(rows[0].EMPNAME);
		//开始时间
		var date1= new Date(rows[0].PLANNIND);
		var kaishi=date1.getFullYear() + '-' + (date1.getMonth() + 1) + '-' +date1.getDate();
		$("#addTrainingPlan_win_strattiametext").datebox("setValue",kaishi);
		//结束时间
		var date2= new Date(rows[0].PLANMAXD);
		var jieshu=date2.getFullYear() + '-' + (date2.getMonth() + 1) + '-' +date2.getDate();
		$("#addTrainingPlan_win_endtimetext").datebox("setValue",jieshu);
		//计划天数PLANTS
		$("#addTrainingPlan_win_daystext").val(rows[0].PLANTS);
		//培训地点
		$("#addTrainingPlan_win_placetext").val(rows[0].plandd);
		//培训内容
		$("#addPaymentt_win_TrainingContents").val(rows[0].PLANNR);
		//培训原因
		$("#addPaymentt_win_TrainingReasons").val(rows[0].PLANYY);
		$("#queding").text("保存");
		$("#addTrainingPlan_win").window("open");
}
//查看
function plan_chakan(){
	var rows=$("#TrainingPlantable").datagrid("getChecked");
	//计划名称
	$("#addTrainingPlan_win_jihuanametext").val(rows[0].planname);
	$("#addTrainingPlan_win_jihuanametext").attr("readonly","readonly");
	//审批人
	//$("#addTrainingPlan_win_chuangjianrentext").val(rows[0].EMPNAME);
	$("#addTrainingPlan_win_chuangjianrentext").attr("disabled",true);
	//开始时间
	var date1= new Date(rows[0].PLANNIND);
	var kaishi=date1.getFullYear() + '-' + (date1.getMonth() + 1) + '-' +date1.getDate();
	$("#addTrainingPlan_win_strattiametext").attr("disabled",true);
	$("#addTrainingPlan_win_strattiametext").datebox("setValue",kaishi);
	
	//结束时间
	var date2= new Date(rows[0].PLANMAXD);
	var jieshu=date2.getFullYear() + '-' + (date2.getMonth() + 1) + '-' +date2.getDate();
	$("#addTrainingPlan_win_endtimetext").attr("disabled",true);
	$("#addTrainingPlan_win_endtimetext").datebox("setValue",jieshu);
	
	//计划天数PLANTS
	$("#addTrainingPlan_win_daystext").val(rows[0].PLANTS);
	//培训地点
	$("#addTrainingPlan_win_placetext").val(rows[0].plandd);
	$("#addTrainingPlan_win_placetext").attr("readonly","readonly");
	//培训内容
	$("#addPaymentt_win_TrainingContents").val(rows[0].PLANNR);
	$("#addPaymentt_win_TrainingContents").attr("readonly","readonly");
	//培训原因
	$("#addPaymentt_win_TrainingReasons").val(rows[0].PLANYY);
	$("#addPaymentt_win_TrainingReasons").attr("readonly","readonly");
	$("#queding").text("确定");
	$("#addTrainingPlan_win").window("open");
}

</script>

<div id="addTrainingPlan_win" class="easyui-window" title="培训计划" style="width:720px;height:500px"
		    		data-options="modal:true,resizable: false,draggable:false,closed:true,minimizable:false,maximizable:false,collapsible:false">
		 			<div id="addTrainingPlan_win_box" class="addTrainingPlan_win_box">
						<a id="addTrainingPlan_win_jihuaname" class="addTrainingPlan_win_text" style="">计划名称：</a>
						<input id="addTrainingPlan_win_jihuanametext" class="addTrainingPlan_win_texts" type="text"/>
					</div>
					<div id="addTrainingPlan_win_box1" class="addTrainingPlan_win_box">
						<a id="addTrainingPlan_win_chuangjianren" class="addTrainingPlan_win_text" style="">审批人：</a>
<!-- 						<input id="addTrainingPlan_win_chuangjianrentext" class=" addTrainingPlan_win_texts" type="text" />
					<select style="width:174px;height:25px;" id="addTrainingPlan_win_chuangjianrentext"> -->
							<c:forEach items="${Plan}" var="p">
<%-- 								<option id="${p.EMPID }" value="${p.EMPNAME}">${p.EMPNAME}</option>
 --%>								<input class="nsb" id="${p.EMPID }"style="width:174px;height:25px;border:none;background:none;"value="${p.EMPNAME}"readonly="readonly"/>
								
							</c:forEach>
							<%-- </select> --%>
					</div>
					<div id="addTrainingPlan_win_box2" class="addTrainingPlan_win_box">
						<a id="addTrainingPlan_win_strattiame" class="addTrainingPlan_win_text" style="">开始时间：</a>
						<input id="addTrainingPlan_win_strattiametext" class="easyui-datebox addTrainingPlan_win_texts" type="text"/>
					</div>
					<div id="addTrainingPlan_win_box3" class="addTrainingPlan_win_box">
						<a id="addTrainingPlan_win_endtime" class="addTrainingPlan_win_text" style="">结束时间：</a>
						<input id="addTrainingPlan_win_endtimetext" class="easyui-datebox addTrainingPlan_win_texts" type="text"/>
					</div>
					<div id="addTrainingPlan_win_box4" class="addTrainingPlan_win_box">
						<a id="addTrainingPlan_win_days" class="addTrainingPlan_win_text" style="">计划天数：</a>
						<input id="addTrainingPlan_win_daystext" class="addTrainingPlan_win_texts" type="text"/>
					</div>
					<div id="addTrainingPlan_win_box5" class="addTrainingPlan_win_box">
						<a id="addTrainingPlan_win_place" class="addTrainingPlan_win_text" style="">培训地点：</a>
						<input id="addTrainingPlan_win_placetext" class=" addTrainingPlan_win_texts" type="text" />
					</div>
					
		 			<div id="addTrainingPlan_win_box6" class="addTrainingPlan_win_box">
						<a id="addTrainingPlan_win_TrainingContents" class="addTrainingPlan_win_text" style="">培训内容：</a>
						<textarea cols="50" rows="10" id="addPaymentt_win_TrainingContents" class="addTrainingContenttext" type="text"></textarea>
					</div>
					<div id="addTrainingPlan_win_box7" class="addTrainingPlan_win_box">
						<a id="addTrainingPlan_win_TrainingReasons" class="addTrainingPlan_win_text" style="">培训原因：</a>
						<textarea cols="50" rows="10" id="addPaymentt_win_TrainingReasons" class="addTrainingContenttext" type="text"></textarea>
					</div>
					<hr id="TrainingReasonsHr">
					<div class="box7s">
						<button id="queding" style="margin-right:15px;">提交</button>
						<button id="quxiao">取消</button>
					</div>
		 		</div>
		 		<div class="head_1">
					<span class="fontstyle">课程名称：</span><input type="text" id="plansname" class="TrainingPlanName"style="    height: 33px;
    line-height: 33px;
    margin-bottom: 20px;">
					<button id="selectTrainingPlan" style="margin-right:15px;">查询</button>
					<button id="addTrainingPlan">新增</button>
				</div>
				<div id="TrainingPlantable_1">
					<table id="TrainingPlantable" class="easyui-datagrid" style="width:100%;height:470px;" data-options="fitColumns:true,singleSelect: true">
					
					</table>
				</div>
</body>
</html>